package com.borball.store.util;

import java.io.FileReader;
import java.io.Reader;

import org.apache.ibatis.session.SqlSessionFactory;
import org.apache.ibatis.session.SqlSessionFactoryBuilder;

public class SessionFactory {

	private static SessionFactory instance;
	String resource = "resources/mapper/Mybatis-Config.xml";
	SqlSessionFactory sqlmapper;
	
	private SessionFactory() {
		init();
	}
	

	private void init() {
		try {
			Reader reader = new FileReader(resource);
			sqlmapper = new SqlSessionFactoryBuilder().build(reader);
		} catch (Exception e) {
			throw new RuntimeException("Initial Session Factory failed, " + e.getMessage());
		}
	}


	public static synchronized SessionFactory getInstance() {
		if (null == instance) {
			instance = new SessionFactory();
		}
		return instance;
	}
	
	public SqlSessionFactory getSqlSessionFactory(){
		return sqlmapper;
	}
	
}
